package com.gitee.sunshine.bean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import com.gitee.sunshine.enums.DBTypeEnum;

public class MyRoutingDataSource extends AbstractRoutingDataSource {
	private static final Logger LOGGER = LoggerFactory.getLogger(MyRoutingDataSource.class);
	
    @Override
    protected Object determineCurrentLookupKey() {
    	DBTypeEnum dbTypeEnum = DBContextHolder.get();
    	LOGGER.info("dbtype:{}",dbTypeEnum);
        return dbTypeEnum == null ? DBTypeEnum.WRITE : dbTypeEnum;
    }

}